﻿using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;

using CCWin;
using CCWin.SkinControl;
using SuperMap.UI;
using SuperMap.Data;
using SuperMap.Mapping;
using SuperMap.Analyst.NetworkAnalyst;
using SuperMap.Analyst.SpatialAnalyst;


namespace MDF
{
    /// <summary>
    /// 多源数据融合系统
    /// </summary>
    public partial class MDF_Main : CCSkinMain
    {
        //初始化变量
        private ZBDW m_zbdw;
        private Workspace m_workspace;
        private DataManage m_DataManage;
        private MapControl m_mapControl;
        private LayersControl m_layersControl;
        private SkinGroupBox m_skinGroupBox;
        
        //判断窗体关闭
        private bool m_bool = false;

        /// <summary>
        /// 记录已匹配的数据
        /// </summary>
        public List<DatasetsMatchResult> datasetsMatchResults;

        /// <summary>
        /// 静态主窗体控制
        /// </summary>
        public static MDF_Main mDF_Main;

        #region 窗体设计和管理
        /// <summary>
        /// 窗体初始化
        /// </summary>
        public MDF_Main()
        {
            LoadCheck m_loadCheck = new LoadCheck();//云许可登入检查
            m_loadCheck.ShowDialog();
            if (m_loadCheck.DialogResult == DialogResult.OK)
            {
                InitializeComponent();

                //系统初始化
                
                Start_Fun();
                
                //静态窗体控制
                mDF_Main = this;
                //释放资源
                m_loadCheck.Dispose();
            }
        }
        /// <summary>
        /// 工作空间初始化
        /// </summary>
        private void Start_Fun()
        {
            try
            {
                //关联地图、工作空间、图层
                m_workspace = new Workspace();
                this.WorkspaceTree_Control.WorkspaceTree.Workspace = m_workspace;
                this.Map_Control1.Map.Workspace = m_workspace;
                this.Layers_Control1.Map = this.Map_Control1.Map;
                //优化UI显示
                Hide_Non_Fun();

                //注册数据源集合右键菜单
                this.WorkspaceTree_Control.WorkspaceTree.NodeContextMenuStrips[WorkspaceTreeNodeDataType.Datasources] = Datasources_ContextMenu;
                //注册数据源右键菜单
                this.WorkspaceTree_Control.WorkspaceTree.NodeContextMenuStrips[WorkspaceTreeNodeDataType.Datasource] = Datasource_ContextMenu;
                //注册数据集右键菜单
                this.WorkspaceTree_Control.WorkspaceTree.NodeContextMenuStrips[WorkspaceTreeNodeDataType.DatasetVector] = DataSets_ContextMenu;
                //注册图层右键菜单
                this.Layers_Control1.LayersTree.NodeContextMenuStrips[LayersTreeNodeDataType.Layer] = Layers_ContextMenu;
                //实例化DataManage
                m_DataManage = new DataManage(m_workspace);
                
                
            }
            catch (Exception)
            {

                throw;
            } 
        }
        /// <summary>
        /// 隐藏非必要功能优化中文显示
        /// </summary>
        private void Hide_Non_Fun()
        {
            try
            {
                //隐藏工作空间相关
                this.WorkspaceTree_Control.LayoutsNodeVisible = false;
                this.WorkspaceTree_Control.MapsNodeVisible = false;
                this.WorkspaceTree_Control.ResourcesNodeVisible = false;
                this.WorkspaceTree_Control.ScenesNodeVisible = false;
                this.WorkspaceTree_Control.WorkspaceToolBar.Visible = false;
                //隐藏图层相关(只展示部分)
                this.Layers_Control1.LayersTree.Icons = TreeIconTypes.TypeIcon | TreeIconTypes.Visible;
                //优化中文显示
                this.WorkspaceTree_Control.WorkspaceTree.WorkspaceNode.Text = "工作空间";
                this.WorkspaceTree_Control.WorkspaceTree.DatasourcesNode.Text = "数据源";
            }
            catch (Exception)
            {
                throw;
            }
        }

        /// <summary>
        /// 添加新地图控件或还原
        /// </summary>
        /// /// <param name="isNewMap">是否新建地图窗口</param>
        private Map New_Map_Fun(bool isNewMap)
        {
            try
            {
                if (isNewMap)
                {
                    //新建一个地图控件
                    m_mapControl = new SuperMap.UI.MapControl
                    {
                        Action = SuperMap.UI.Action.Pan,
                        BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(192)))), ((int)(((byte)(255)))), ((int)(((byte)(255))))),
                        BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle,
                        Dock = System.Windows.Forms.DockStyle.Fill,
                        ForeColor = System.Drawing.Color.Black,
                        Location = new System.Drawing.Point(1, 16),
                        Margin = new System.Windows.Forms.Padding(48, 22, 48, 22),
                        Name = "Map_Control2",
                        Size = new System.Drawing.Size(1370, 607),
                        TabIndex = 0,
                        TrackMode = SuperMap.UI.TrackMode.Edit,
                    };
                    //新建一个地图控件容器
                    m_skinGroupBox = new CCWin.SkinControl.SkinGroupBox
                    {
                        BackColor = System.Drawing.Color.Transparent,
                        BorderColor = System.Drawing.Color.Transparent,
                        CausesValidation = false,
                        Dock = System.Windows.Forms.DockStyle.Right,
                        Font = new System.Drawing.Font("楷体", 10.5F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(134))),
                        ForeColor = System.Drawing.Color.Black,
                        Location = new System.Drawing.Point(686, 0),
                        Name = "Map_Box2",
                        Padding = new System.Windows.Forms.Padding(1, 0, 0, 1),
                        RectBackColor = System.Drawing.Color.Transparent,
                        RoundStyle = CCWin.SkinClass.RoundStyle.All,
                        Size = new System.Drawing.Size(685, 624),
                        TabIndex = 0,
                        TabStop = false,
                        Text = "地图",
                        TitleBorderColor = System.Drawing.Color.Transparent,
                        TitleRectBackColor = System.Drawing.Color.Transparent,
                        TitleRoundStyle = CCWin.SkinClass.RoundStyle.Top
                    };
                    //绑定工作空间
                    this.m_mapControl.Map.Workspace = m_workspace;
                    //绑定事件
                    this.m_mapControl.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Map_Control_MouseDown);
                    this.m_skinGroupBox.Click += new System.EventHandler(this.Map_Box_Click);
                    //向容器中添加控件
                    m_skinGroupBox.Controls.Add(m_mapControl);
                    this.Map_Panel.Controls.Add(m_skinGroupBox);

                    //返回地图
                    return m_mapControl.Map;
                }
                else
                {
                    //先移除控件
                    this.Map_Panel.Controls.Remove(m_skinGroupBox);
                    this.Tree_Panel.Controls.Remove(m_layersControl);
                    //释放资源
                    m_mapControl.Dispose();
                    m_skinGroupBox.Dispose();
                    m_layersControl.Dispose();
                    //显示原图层控件
                    this.Layers_Control1.Visible = true;

                    return null;
                }
                
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 添加新图层控件
        /// </summary>
        /// <param name="m_map">新地图控件中的地图</param>
        /// <returns></returns>
        private Layers New_Layers_Fun(Map m_map)
        {
            try
            {
                //新建图层控件
                m_layersControl = new LayersControl
                {
                    BackColor = System.Drawing.Color.White,
                    BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle,
                    Dock = System.Windows.Forms.DockStyle.Bottom,
                    Font = new System.Drawing.Font("楷体", 10.5F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))),
                    Location = new System.Drawing.Point(0, 453),
                    Map = null,
                    Name = "Layers_Control2",
                    Scene = null,
                    Size = new System.Drawing.Size(221, 451),
                    TabIndex = 1,
                    Visible = true
                };
                //绑定地图
                m_layersControl.Map = m_map;
                //隐藏原有图层控件
                this.Layers_Control1.Visible = false;
                //隐藏图层相关(只展示部分)
                this.m_layersControl.LayersTree.Icons = TreeIconTypes.TypeIcon | TreeIconTypes.Visible;
                //添加新图层控件
                this.Tree_Panel.Controls.Add(m_layersControl);
                //绑定右键菜单
                m_layersControl.LayersTree.NodeContextMenuStrips[LayersTreeNodeDataType.Layer] = Layers_ContextMenu;
                //返回图层
                return m_layersControl.Map.Layers;
            }
            catch (Exception)
            {

                throw;
            }
            
        }
        /// <summary>
        /// 点击地图容器时刷新图层显示
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Map_Box_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.m_layersControl != null)//判断是否有新的地图控件
                {
                    SkinGroupBox skinGroupBox = (SkinGroupBox)sender;
                    if (skinGroupBox.Name.Contains("1"))
                    {
                        this.Layers_Control1.Visible = true;
                        this.m_layersControl.Visible = false;
                    }
                    else
                    {
                        this.Layers_Control1.Visible = false;
                        this.m_layersControl.Visible = true;
                    }
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 调整地图控件状态
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Map_Control_MouseDown(object sender, MouseEventArgs e)
        {
            try
            {
                MapControl mapControl = (MapControl)sender;
                //禁止右键点击，使控件变为选择状态
                if (e.Button == MouseButtons.Right)
                {
                    mapControl.Action = SuperMap.UI.Action.Pan;
                }
                //对应图层控件获取焦点
                if (this.m_layersControl != null)
                {
                    if (mapControl.Name.Contains("1"))
                    {
                        this.Layers_Control1.Visible = true;
                        this.m_layersControl.Visible = false;
                    }
                    else
                    {
                        this.Layers_Control1.Visible = false;
                        this.m_layersControl.Visible = true;
                    }
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 鼠标选择后，松开时发生
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Map_Control_MouseUp(object sender, MouseEventArgs e)
        {
            try
            {
                //判断是否左键松开
                if (e.Button == MouseButtons.Left)
                {
                    //判断选择的地图控件
                    if (this.Map_Control1.Action == SuperMap.UI.Action.Select2)
                    {
                        int count = 0;//获取选择对象个数
                        foreach (Selection selection in this.Map_Control1.Map.FindSelection(true))
                        {
                            count += selection.Count;
                        }
                        SJPPXZYS.m_xZYS.SelectsCount_Label.Text = "已选择要素个数："+ count.ToString();
                    }
                    else
                    {
                        int count = 0;//获取选择对象个数
                        foreach (Selection selection in this.m_mapControl.Map.FindSelection(true))
                        {
                            count += selection.Count;
                        }
                        SJPPXZYS.m_xZYS.SelectsCount_Label.Text = "已选择要素个数：" + count.ToString();
                    }
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 公开方法：控制地图控件的活动模式
        /// </summary>
        /// <param name="sleMode">地图控件展示的模式。-1表示还原、0表示修改第一个地图控件、1表示修改新添加的地图控件</param>
        public void Map_Control1_Select(int sleMode)
        {
            try
            {
                //判断处理模式
                switch (sleMode)
                {
                    case -1:
                        //还原两个地图控件的右键效果
                        this.Map_Control1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Map_Control_MouseDown);
                        this.Map_Control1.MouseUp -= new System.Windows.Forms.MouseEventHandler(this.Map_Control_MouseUp);
                        this.Map_Control1.Action = SuperMap.UI.Action.Pan;
                        if (this.m_mapControl != null)
                        {
                            this.m_mapControl.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Map_Control_MouseDown);
                            this.m_mapControl.MouseUp -= new System.Windows.Forms.MouseEventHandler(this.Map_Control_MouseUp);
                            this.m_mapControl.Action = SuperMap.UI.Action.Pan;
                        }
                        break;
                    case 0:
                        //移除地图控件1的右键效果
                        this.Map_Control1.MouseDown -= new System.Windows.Forms.MouseEventHandler(this.Map_Control_MouseDown);
                        //添加选择效果
                        this.Map_Control1.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Map_Control_MouseUp);
                        this.Map_Control1.Action = SuperMap.UI.Action.Select2;
                        //还原新地图控件效果
                        if (this.m_mapControl != null)
                        {
                            this.m_mapControl.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Map_Control_MouseDown);
                            this.m_mapControl.MouseUp -= new System.Windows.Forms.MouseEventHandler(this.Map_Control_MouseUp);
                            this.m_mapControl.Action = SuperMap.UI.Action.Pan;
                        }
                        break;
                    case 1:
                        //移除新地图控件原有右键效果
                        this.m_mapControl.MouseDown -= new System.Windows.Forms.MouseEventHandler(this.Map_Control_MouseDown);
                        //添加选择效果
                        this.m_mapControl.MouseUp += new System.Windows.Forms.MouseEventHandler(this.Map_Control_MouseUp);
                        this.m_mapControl.Action = SuperMap.UI.Action.Select2;
                        //还原地图控件1的右键效果
                        if (this.Map_Control1.Action == SuperMap.UI.Action.Select2)
                        {
                            this.Map_Control1.MouseDown += new System.Windows.Forms.MouseEventHandler(this.Map_Control_MouseDown);
                            this.Map_Control1.MouseUp -= new System.Windows.Forms.MouseEventHandler(this.Map_Control_MouseUp);
                            this.Map_Control1.Action = SuperMap.UI.Action.Pan;
                        }
                        break;
                    default:
                        //刷新一下地图，清空选择
                        if (this.Map_Control1.Action == SuperMap.UI.Action.Select2)
                        {
                            foreach (Layer layer in this.Map_Control1.Map.Layers)
                            {
                                layer.Selection.Clear();
                            }
                            this.Map_Control1.Map.Refresh();
                        }
                        else if (this.m_mapControl != null)
                        {
                            foreach (Layer layer in this.m_mapControl.Map.Layers)
                            {
                                layer.Selection.Clear();
                            }
                            this.m_mapControl.Map.Refresh();
                        }
                        break;
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 窗体关闭时，释放资源
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MDF_Main_FormClosing(object sender, FormClosingEventArgs e)
        {
            try
            {
                if (m_bool)
                {
                    this.Map_Control1.Dispose();
                    this.m_workspace.Dispose();
                }
                else
                {
                    if (m_workspace.Datasources.Count > 0)
                    {
                        if (MessageBox.Show("你有已打开的数据源，是否退出程序？", "保存提示：", MessageBoxButtons.OKCancel) == DialogResult.OK)
                        {
                            if (m_layersControl != null)//判断是否使用了新地图控件
                            {
                                this.m_layersControl.Dispose();
                                this.m_mapControl.Dispose();
                                this.m_skinGroupBox.Dispose();
                            }
                            this.Map_Control1.Dispose();
                            this.m_workspace.Dispose();

                            System.Environment.Exit(0);
                        }
                        else
                        {
                            e.Cancel = true;
                        }
                    }
                    else
                    {
                        this.Map_Control1.Dispose();
                        this.m_workspace.Dispose();
                        System.Environment.Exit(0);
                    }
                }               
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        /// <summary>
        /// 退出程序
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Exit_Main_Click(object sender, EventArgs e)
        {
            try
            {
                if (m_workspace.Datasources.Count > 0)
                {
                    if (MessageBox.Show("你有已打开的数据源，是否退出程序？", "保存提示：", MessageBoxButtons.OKCancel) == DialogResult.OK)
                    {
                        m_bool = true;
                        System.Environment.Exit(0);
                    }
                }
                else
                {
                    System.Environment.Exit(0);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        #endregion

        #region “文件”功能与右键菜单功能


        /// <summary>
        /// 打开数据源
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Open_DataSource_Click(object sender, EventArgs e)
        {
            try
            {
                //获取数据源路径
                OpenFile_Dialog.FileName = "";
                OpenFile_Dialog.Filter = "UDB引擎|*.udb|所有文件|*.*";
                if (OpenFile_Dialog.ShowDialog() == DialogResult.OK)
                {
                    string fileName = Path.GetFileNameWithoutExtension(OpenFile_Dialog.FileName);
                    if (!m_workspace.Datasources.Contains(fileName))
                    {
                        m_DataManage.OpenDatasource(OpenFile_Dialog.FileName);
                    }
                    else
                    {
                        MessageBox.Show("数据源已存在！", "提示：");
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        /// <summary>
        /// 保存默认数据源
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Save_DataSource_Click(object sender, EventArgs e)
        {
            try
            {
                string sourceName = this.WorkspaceTree_Control.WorkspaceTree.SelectedNode.Text;
                //判断数据源是否打开
                if (m_workspace.Datasources[sourceName] != null)
                {

                    //获取数据源存放路径及名称
                    SaveFile_Dialog.Filter = "UDB引擎|*.udb|所有文件|*.*";
                    SaveFile_Dialog.FileName = "DataSource_1";
                    if (SaveFile_Dialog.ShowDialog() == DialogResult.OK)
                    {

                        //保存数据源
                        m_DataManage.SaveDataSource(sourceName,SaveFile_Dialog.FileName);
                        //关闭数据源
                        this.WorkspaceTree_Control.WorkspaceTree.SelectedNode = this.WorkspaceTree_Control.WorkspaceTree.DatasourcesNode.Nodes[sourceName];
                        Close_DataSource_Click(sender, e);

                    }
                }
                else
                {
                    MessageBox.Show(sourceName+"数据源不存在！", "提示：");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        /// <summary>
        /// 新建数据源
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Create_DataSource_Click(object sender, EventArgs e)
        {
            //获取数据源存放路径及名称
            SaveFile_Dialog.Filter = "UDB引擎|*.udb|所有文件|*.*";
            SaveFile_Dialog.FileName = "DataSource_1";
            Map map = this.Map_Control1.Map;
            if (SaveFile_Dialog.ShowDialog() == DialogResult.OK)
            {
                m_DataManage.CreateDataSource(SaveFile_Dialog.FileName);
            }
        }
        /// <summary>
        /// 关闭数据源
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Close_DataSource_Click(object sender, EventArgs e)
        {
            try
            {
                
                //获取选中节点的数据源
                string sourceAlias = this.WorkspaceTree_Control.WorkspaceTree.SelectedNode.Text;
                Datasource datasource = m_workspace.Datasources[sourceAlias];

                //获取地图窗口和已展示的图层
                List<Map> maps = new List<Map>();
                List<Layers> layersS = new List<Layers>();
                maps.Add(this.Map_Control1.Map);
                layersS.Add(this.Layers_Control1.Map.Layers);
                //查看第二控件是否启用
                if (this.m_layersControl != null && this.m_layersControl.Map.Layers != null)
                {
                    //添加第二控件内容
                    maps.Add(this.m_mapControl.Map);
                    layersS.Add(this.m_layersControl.Map.Layers);
                }

                //关闭数据源
                string[] setsName = m_DataManage.CloseSource(maps.ToArray(),layersS.ToArray(), datasource);
                if (setsName.Length > 0)
                {
                    //判断该数据源属性表是否已经打开
                    if (setsName.Contains(this.Name_DataTable_lab.Text + "@" + sourceAlias))
                    {
                        this.Data_Table.Rows.Clear();
                        this.Data_Table.Columns.Clear();
                        this.Name_DataTable_lab.Text = "属性表";
                    }
                }

                //判断是否关闭第二地图控件
                if (this.m_layersControl != null && this.m_layersControl.Map.Layers == null)
                {
                    New_Map_Fun(false);//还原界面
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 关闭所有数据源
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CloseAll_Sources_Click(object sender, EventArgs e)
        {
            try
            {
                if(MessageBox.Show("确认关闭所有数据源？", "删除提示：", MessageBoxButtons.OKCancel) == DialogResult.OK)
                {
                    //判断第二控件是否存在
                    if (this.m_layersControl != null)
                    {
                        this.m_layersControl.Map.Layers.Clear();
                        this.m_mapControl.Map.Refresh();
                        New_Map_Fun(false);//还原界面
                    }
                    //判断第一控件是否使用
                    if (this.Layers_Control1.Map.Layers != null)
                    {
                        this.Layers_Control1.Map.Layers.Clear();
                        this.Map_Control1.Map.Refresh();
                    }
                    //关闭所有数据源
                    m_workspace.Datasources.CloseAll();
                    //刷新工作空间树
                    this.WorkspaceTree_Control.WorkspaceTree.RefreshNode(this.WorkspaceTree_Control.WorkspaceTree.DatasourcesNode);



                }
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 打开数据文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Open_Set_Click(object sender, EventArgs e)
        {
            try
            {
                //获取数据集路径
                OpenFile_Dialog.FileName = "";
                OpenFile_Dialog.Filter = "shp文件|*.shp|geojson文件|*.geojson;*.json|dwg文件|*.dwg|所有文件|*.*";
                if (OpenFile_Dialog.ShowDialog() == DialogResult.OK)
                {
                    //切换对应的数据源
                    m_DataManage.ChangeDatasource(this.WorkspaceTree_Control.WorkspaceTree.SelectedNode.Text);
                    //再打开数据文件
                    m_DataManage.OpenFile(OpenFile_Dialog.FileName);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }       
        /// <summary>
        /// 另存数据文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SaveOther_Set_Click(object sender, EventArgs e)
        {
            try
            {
                SaveFile_Dialog.Filter = "shp文件|*.shp|geojson文件|*.json|所有文件|*.*";
                SaveFile_Dialog.FileName = "Ecport_1";
                WorkspaceTreeNodeBase selectNode = this.WorkspaceTree_Control.WorkspaceTree.SelectedNode as WorkspaceTreeNodeBase;//获取选中节点
                //获取数据存放路径及名称
                if (SaveFile_Dialog.ShowDialog() == DialogResult.OK)
                {
                    m_DataManage.SaveOtherFile(SaveFile_Dialog.FileName, selectNode);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        /// <summary>
        /// 设置管理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Setting_Main_Click(object sender, EventArgs e)
        {
            try
            {
                //实例化管理窗口
                SZGL m_sZGL = new SZGL();
                m_sZGL.ShowDialog();
                if(m_sZGL.DialogResult == DialogResult.OK)
                {
                    //释放资源
                    m_sZGL.Dispose();
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 删除数据集
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Delete_Set_Click(object sender, EventArgs e)
        {
            try
            {
                //获取选中节点
                WorkspaceTreeNodeBase selectNode = this.WorkspaceTree_Control.WorkspaceTree.SelectedNode as WorkspaceTreeNodeBase;
                //获取所在的数据源
                Datasource datasource = m_workspace.Datasources[0];
                if (selectNode.Parent.GetType().Name == "WorkspaceTreeNodeDatasource")
                {
                    datasource = m_workspace.Datasources[selectNode.Parent.Name];
                }
                else if (selectNode.Parent.Parent.GetType().Name == "WorkspaceTreeNodeDatasource")
                {
                    datasource = m_workspace.Datasources[selectNode.Parent.Parent.Name];
                }

                //获取地图窗口和已展示的图层
                List<Map> maps = new List<Map>();
                List<Layers> layersS = new List<Layers>();
                maps.Add(this.Map_Control1.Map);
                layersS.Add(this.Layers_Control1.Map.Layers);
                //查看第二控件是否启用
                if(this.m_layersControl != null && this.m_layersControl.Map.Layers != null)
                {
                    //添加第二控件内容
                    maps.Add(this.m_mapControl.Map);
                    layersS.Add(this.m_layersControl.Map.Layers);
                }
                //调用删除方法
                m_DataManage.DeleteSet(maps.ToArray(), layersS.ToArray(), datasource, selectNode);
                //判断该数据属性表是否已经打开
                if (this.Name_DataTable_lab.Text.Equals(selectNode.Text))
                {
                    this.Data_Table.Rows.Clear();
                    this.Data_Table.Columns.Clear();
                    this.Name_DataTable_lab.Text = "属性表";
                }
                //判断是否关闭第二地图控件
                if (this.m_layersControl != null && this.m_layersControl.Map.Layers == null)
                {
                    New_Map_Fun(false);//还原界面
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        /// <summary>
        /// 重命名数据集(待优化)
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ReName_Set_Click(object sender, EventArgs e)
        {
            try
            {
                System.Windows.Forms.SendKeys.Send("{F2}");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        /// <summary>
        /// 打开选中数据集的属性表，不可编辑
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Open_DataTable_Click(object sender, EventArgs e)
        {
            try
            {
                DataGridView dataGridView = this.Data_Table;//获取当前工作表
                WorkspaceTreeNodeBase selectNode = this.WorkspaceTree_Control.WorkspaceTree.SelectedNode as WorkspaceTreeNodeBase;//获取选中节点
                if (!this.Name_DataTable_lab.Text.Equals(selectNode.Text))//判断该数据属性表是否已经打开
                {
                    //给属性表赋名
                    this.Name_DataTable_lab.Text = selectNode.Text;
                    //调用加载方法
                    m_DataManage.OpenDataTable(dataGridView, selectNode);
                } 
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        /// <summary>
        /// 将数据集加载到地图窗口，不可编辑
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToMap_Set_Click(object sender, EventArgs e)
        {
            try
            {
                Map map = this.Map_Control1.Map;//获取地图窗口
                Layers layers = this.Layers_Control1.Map.Layers;//获取已展示的图层
                WorkspaceTreeNodeBase selectNode = this.WorkspaceTree_Control.WorkspaceTree.SelectedNode as WorkspaceTreeNodeBase;//获取选中节点
                
                //判断是否创建新地图窗口
                if (sender.ToString().Length == 6)
                { 
                    if (this.Tree_Panel.Controls.Count == 2)
                    {
                        map = New_Map_Fun(true); //获取新地图窗口
                        layers = New_Layers_Fun(map);//获取新图层控件的图层
                    }
                    else
                    {
                        map = this.m_mapControl.Map; //获取新地图窗口
                        layers = this.m_layersControl.Map.Layers;//获取新图层控件的图层
                        //显示对应图层控件
                        this.Layers_Control1.Visible = false;
                        this.m_layersControl.Visible = true;
                    }
                    //更新名称
                    this.m_skinGroupBox.Text = selectNode.Text;
                }
                else
                {
                    //显示对应图层控件
                    if (this.m_layersControl != null)
                    {
                        this.Layers_Control1.Visible = true;
                        this.m_layersControl.Visible = false;
                    }
                    //更新名称
                    this.Map_Box1.Text = selectNode.Text;
                }
                //设置地图名字
                map.Name = selectNode.Text;
                //调用加载方法
                m_DataManage.ToMapSet(map, layers, selectNode);
                
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        #endregion

        #region 图层右键菜单
        /// <summary>
        /// 展示图层
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Show_Layers_Click(object sender, EventArgs e)
        {
            try
            {

                if (this.Layers_Control1.Visible)//原控件
                {
                    if (this.Layers_Control1.LayersTree.SelectedNodes != null)//获取用户选中的节点
                    {
                        this.Map_Control1.Map.Layers[this.Layers_Control1.LayersTree.SelectedNode.Index].IsVisible = true;
                        this.Map_Control1.Map.Refresh();
                    }
                    else
                    {
                        MessageBox.Show("请选择至少一个需要打开的图层！","提示：");
                    }
                }
                else//新控件
                {
                    if (this.m_layersControl.LayersTree.SelectedNodes != null)//获取用户选中的节点
                    {
                        this.m_mapControl.Map.Layers[this.m_layersControl.LayersTree.SelectedNode.Index].IsVisible = true;
                        this.m_mapControl.Map.Refresh();
                    }
                    else
                    {
                        MessageBox.Show("请选择至少一个需要打开的图层！", "提示：");
                    }
                }
                
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 隐藏图层
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Hide_Layers_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.Layers_Control1.Visible)//原控件
                {
                    if (this.Layers_Control1.LayersTree.SelectedNodes != null)//获取用户选中的节点
                    {
                        this.Map_Control1.Map.Layers[this.Layers_Control1.LayersTree.SelectedNode.Index].IsVisible = false;
                        this.Map_Control1.Map.Refresh();
                    }
                    else
                    {
                        MessageBox.Show("请选择至少一个需要隐藏的图层！", "提示：");
                    }
                }
                else//新控件
                {
                    if (this.m_layersControl.LayersTree.SelectedNodes != null)//获取用户选中的节点
                    {
                        this.m_mapControl.Map.Layers[this.m_layersControl.LayersTree.SelectedNode.Index].IsVisible = false;
                        this.m_mapControl.Map.Refresh();
                    }
                    else
                    {
                        MessageBox.Show("请选择至少一个需要隐藏的图层！", "提示：");
                    }
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 移除图层
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Remove_Layers_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.Layers_Control1.Visible)//原控件
                {
                    if (this.Layers_Control1.LayersTree.SelectedNodes != null)//获取用户选中的节点
                    {
                        foreach (LayersTreeNodeBase layersTreeNodeBase in this.Layers_Control1.LayersTree.SelectedNodes)
                        {
                            //移除图层
                            this.Layers_Control1.Map.Layers.Remove(layersTreeNodeBase.Name);
                            this.Map_Control1.Map.Refresh();
                            //还原名称
                            this.Map_Box1.Text = "地图";
                        }
                    }
                    else
                    {
                        MessageBox.Show("请选择至少一个需要移除的图层！", "提示：");
                    }
                }
                else//新控件
                {
                    if (this.m_layersControl.LayersTree.SelectedNodes != null)//获取用户选中的节点
                    {
                        foreach (LayersTreeNodeBase layersTreeNodeBase in this.m_layersControl.LayersTree.SelectedNodes)
                        {
                            this.m_layersControl.Map.Layers.Remove(layersTreeNodeBase.Name);
                            this.m_mapControl.Map.Refresh();
                        }
                        if(this.m_layersControl.Map.Layers.Count == 0)
                        {
                            New_Map_Fun(false);//还原界面
                        }
                    }
                    else
                    {
                        MessageBox.Show("请选择至少一个需要移除的图层！", "提示：");
                    }
                }
                
            }
            catch (Exception)
            {

                throw;
            }
        }
        #endregion

        #region MDF主菜单功能
        /// <summary>
        /// 坐标定位
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CoordinatePositioning_Click(object sender, EventArgs e)
        {
            try
            {
                //设置窗体第一次应该出现的位置
                Point point = new Point(this.Location.X + this.Map_Panel.Location.X + this.Map_Control1.Location.X + 3, this.Location.Y + this.Map_Panel.Location.Y + this.Map_Control1.Location.Y + 3);
                List<Map> maps = new List<Map>();
                maps.Add(this.Map_Control1.Map);
                if (this.m_mapControl != null)
                {
                    maps.Add(this.m_mapControl.Map);
                }
                if (m_zbdw == null || m_zbdw.IsDisposed)
                {
                    //实例坐标定位（以第一地图为准）
                    m_zbdw = new ZBDW(maps.ToArray());
                    m_zbdw.Location = point;
                    m_zbdw.Show();
                }
                else
                {
                    m_zbdw.Location = point;
                    m_zbdw.MapCenter_ToText();
                    m_zbdw.Activate();
                }
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message); ;
            }
        }

        #region 数据校正
        /// <summary>
        /// 投影变换
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Projection_Transformation_Click(object sender, EventArgs e)
        {
            try
            {
                int setsCount = 0;
                foreach (Datasource datasource in m_workspace.Datasources)
                {
                    setsCount += datasource.Datasets.Count;
                }
                if(setsCount > 0)
                {
                    //实例化一个投影变换窗体
                    SJJZTY m_SJJZTY = new SJJZTY(m_workspace.Datasources);
                    if (m_SJJZTY.ShowDialog() == DialogResult.OK)
                    {
                        if(m_SJJZTY.setInfo != "")
                        {
                            //获取数据集所在的地图窗口
                            List<Map> maps = new List<Map>();
                            List<Layers> layersS = new List<Layers>();
                            if (this.Layers_Control1.Map.Layers.Contains(m_SJJZTY.setInfo))
                            {
                                //获取地图窗口和已展示的图层
                                maps.Add(this.Map_Control1.Map);
                                layersS.Add(this.Layers_Control1.Map.Layers);
                            }
                            if(this.m_layersControl != null && this.m_layersControl.Map.Layers.Contains(m_SJJZTY.setInfo))
                            {
                                //获取地图窗口和已展示的图层
                                maps.Add(this.m_mapControl.Map);
                                layersS.Add(this.m_layersControl.Map.Layers);
                            }
                            string setName = m_SJJZTY.setInfo.Split('@')[0];
                            //获取数据集对应节点
                            WorkspaceTreeNodeBase selectNode = this.WorkspaceTree_Control.WorkspaceTree.Nodes.Find(setName,true)[0] as WorkspaceTreeNodeBase;
                            for (int i = 0; i < maps.Count; i++)
                            {
                                //重新加载
                                m_DataManage.ToMapSet(maps[0],layersS[0],selectNode);
                            }
                        }
                        //释放窗体资源
                        m_SJJZTY.Dispose();
                    }
                    else
                    {
                        //释放窗体资源
                        m_SJJZTY.Dispose();
                    }
                }
                else
                {
                    MessageBox.Show("当前数据源数据集不足！", "提示：");
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 属性修改
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Attribute_Transformation_Click(object sender, EventArgs e)
        {
            try
            {
                int setsCount = 0;
                foreach (Datasource datasource in m_workspace.Datasources)
                {
                    setsCount += datasource.Datasets.Count;
                }
                if (setsCount > 0)
                {
                    //实例化属性修改对象
                    SJJZSX m_SJJZSX = new SJJZSX(m_workspace);
                    m_SJJZSX.ShowDialog();
                    //释放资源
                    m_SJJZSX.Dispose();
                }
                else
                {
                    MessageBox.Show("当前数据源数据集不足！", "提示：");
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 构建网络数据集
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BuildNetwork_Transformation_Click(object sender, EventArgs e)
        {
            try
            {
                if (m_workspace.Datasources[0] != null)
                {
                    TPWSJJ m_TPWSJJ = new TPWSJJ(m_workspace.Datasources[0]);
                    m_TPWSJJ.ShowDialog();//创建“构建网络数据集”窗口
                    if (m_TPWSJJ.DialogResult == DialogResult.OK)
                    {
                        string lineName, pointName;
                        DatasetVector Dt_network;
                        DatasetVector[] LineDatasetVectors = new DatasetVector[m_TPWSJJ.LineNames.Length];//获取线数据集集合
                        for (int i = 0; i < m_TPWSJJ.LineNames.Length; i++)
                        {
                            lineName = m_TPWSJJ.LineNames[i];
                            LineDatasetVectors[i] = m_workspace.Datasources[0].Datasets[m_TPWSJJ.LineNames[i]] as DatasetVector;
                        }
                        if (m_TPWSJJ.PointNames != null)
                        {
                            DatasetVector[] PointDatasetVectors = new DatasetVector[m_TPWSJJ.PointNames.Length];//获取点数据集集合
                            for (int i = 0; i < m_TPWSJJ.PointNames.Length; i++)
                            {
                                pointName = m_TPWSJJ.PointNames[i];
                                PointDatasetVectors[i] = m_workspace.Datasources[0].Datasets[m_TPWSJJ.PointNames[i]] as DatasetVector;
                            }
                            Dt_network = NetworkBuilder.BuildNetwork(LineDatasetVectors, PointDatasetVectors, m_TPWSJJ.LineFielinfos, m_TPWSJJ.PointFielinfos, m_workspace.Datasources[0], m_workspace.Datasources[0].Datasets.GetAvailableDatasetName(m_TPWSJJ.SaveName), m_TPWSJJ.NetworkSplitMode, m_TPWSJJ.RongXian);
                        }
                        else
                        {
                            Dt_network = NetworkBuilder.BuildNetwork(LineDatasetVectors, null, m_TPWSJJ.LineFielinfos, null, m_workspace.Datasources[0], m_workspace.Datasources[0].Datasets.GetAvailableDatasetName(m_TPWSJJ.SaveName), m_TPWSJJ.NetworkSplitMode, m_TPWSJJ.RongXian);
                        }
                    }
                    m_TPWSJJ.Dispose();
                }
                else
                {
                    MessageBox.Show("数据源为空！");
                }
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message); ;
            }
        }
        #endregion

        #region 空间匹配
        /// <summary>
        /// 空间阈值
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Spatial_Threshold_Click(object sender, EventArgs e)
        {
            try
            {
                //实例化空间阈值窗体
                SJPPYZ m_sJPPYZ = new SJPPYZ(m_workspace.Datasources);
                m_sJPPYZ.Name = "KJPPYZ";
                m_sJPPYZ.FillSets();
                //对话模式窗体
                m_sJPPYZ.ShowDialog();
                m_sJPPYZ.Dispose();
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 选择集匹配
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SelectData_MatchingSpace_Click(object sender, EventArgs e)
        {
            try
            {
                //获取当前展示的地图窗口的地图集合
                Map[] m_Maps = new Map[] { this.Map_Control1.Map };
                if (this.m_mapControl != null)
                {
                    m_Maps = new Map[] { this.Map_Control1.Map, this.m_mapControl.Map };
                }
                //判断窗体是否打开(因为是非对话模式窗口)
                List<string> formNames = new List<string>();
                foreach (Form form in Application.OpenForms)
                {
                    formNames.Add(form.Name);
                }
                if (formNames.Contains("KJPP"))
                {
                    Application.OpenForms["KJPP"].Activate();
                }
                else
                {
                    //实例化选择集窗体
                    SJPP m_KongJianPiPei = new SJPP(m_Maps,m_workspace.Datasources);
                    m_KongJianPiPei.Name = "KJPP";
                    m_KongJianPiPei.Crate_m_Xml();
                    m_KongJianPiPei.FillSets();
                    m_KongJianPiPei.Show();
                }
                

            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 数据集匹配
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Dataset_MatchingSpace_Click(object sender, EventArgs e)
        {
            try
            {
                //统计所有数据源中的数据集
                int count = 0;
                foreach (Datasource datasource in m_workspace.Datasources)
                {
                    count += datasource.Datasets.Count;
                }
                if (count > 1)
                {
                    //实例化数据集窗体，传递当前的数据源集合
                    SJPP m_KongJianPiPei = new SJPP(m_workspace.Datasources);
                    m_KongJianPiPei.Name = "KJPP";
                    m_KongJianPiPei.Crate_m_Xml();
                    m_KongJianPiPei.FillSets();
                    m_KongJianPiPei.ShowDialog();
                    m_KongJianPiPei.Dispose();
                }
                else
                {
                    MessageBox.Show("数据源数据集不足！", "提示：");
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
        #endregion

        #region 属性匹配
        /// <summary>
        /// 字段映射
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Attribute_Mapping_Click(object sender, EventArgs e)
        {
            try
            {
                //统计所有数据源中的数据集
                int count = 0;
                foreach (Datasource datasource in m_workspace.Datasources)
                {
                    count += datasource.Datasets.Count;
                }
                if (count > 1)
                {
                    //属性映射实例
                    SXPPYS m_Sxys = new SXPPYS(m_workspace.Datasources);
                    m_Sxys.ShowDialog();
                    m_Sxys.Dispose();
                }
                else
                {
                    MessageBox.Show("数据源数据集不足！","提示：");
                }
            }
            catch (Exception ex)
            {

                MessageBox.Show(ex.Message); ;
            }
        }
        /// <summary>
        /// 语义字典
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Semantic_Dictionary_Click(object sender, EventArgs e)
        {
            try
            {
                //实例化字典窗口
                SXPPZD m_SXPPZD = new SXPPZD();
                m_SXPPZD.ShowDialog();
                m_SXPPZD.Dispose();
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 选择集匹配
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SelectionData_MatchingAttribute_Click(object sender, EventArgs e)
        {
            try
            {
                //获取当前展示的地图窗口的地图集合
                Map[] m_Maps = new Map[] { this.Map_Control1.Map };
                if (this.m_mapControl != null)
                {
                    m_Maps = new Map[] { this.Map_Control1.Map, this.m_mapControl.Map };
                }
                //判断窗体是否打开(因为是非对话模式窗口)
                List<string> formNames = new List<string>();
                foreach (Form form in Application.OpenForms)
                {
                    formNames.Add(form.Name);
                }
                if (formNames.Contains("SXPP"))
                {
                    Application.OpenForms["SXPP"].Activate();
                }
                else
                {
                    //实例化选择集窗体
                    SJPP m_ShuXingPiPei = new SJPP(m_Maps, m_workspace.Datasources);
                    m_ShuXingPiPei.Name = "SXPP";
                    m_ShuXingPiPei.Crate_m_Xml();
                    m_ShuXingPiPei.FillSets();
                    m_ShuXingPiPei.Show();
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 数据集匹配
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Dataset_MatchingAttribute_Click(object sender, EventArgs e)
        {
            try
            {
                //统计所有数据源中的数据集
                int count = 0;
                foreach (Datasource datasource in m_workspace.Datasources)
                {
                    count += datasource.Datasets.Count;
                }
                if (count > 1)
                {
                    //实例化选择集窗体，传递当前的数据源集合
                    SJPP m_ShuXingPiPei = new SJPP(m_workspace.Datasources);
                    m_ShuXingPiPei.Name = "SXPP";
                    m_ShuXingPiPei.Crate_m_Xml();
                    m_ShuXingPiPei.FillSets();
                    m_ShuXingPiPei.ShowDialog();
                    m_ShuXingPiPei.Dispose();
                }
                else
                {
                    MessageBox.Show("数据源数据集不足！", "提示：");
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
        #endregion

        #region 拓扑匹配
        /// <summary>
        /// 拓扑处理
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Topology_Preprocessing_Click(object sender, EventArgs e)
        {
            try
            {
                //实例化拓扑处理窗体
                SJPPYZ m_sJPPTP = new SJPPYZ(m_workspace.Datasources);
                m_sJPPTP.Name = "TPPPYZ";
                m_sJPPTP.ChangeForm();
                m_sJPPTP.FillSets();
                //对话模式窗体
                m_sJPPTP.ShowDialog();
                m_sJPPTP.Dispose();
            }
            catch (Exception)
            {

                throw;
            }
        }

        /// <summary>
        /// 选择集匹配
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SelectData_MatchingTopology_Click(object sender, EventArgs e)
        {
            try
            {
                //获取当前展示的地图窗口的地图集合
                Map[] m_Maps = new Map[] { this.Map_Control1.Map };
                if (this.m_mapControl != null)
                {
                    m_Maps = new Map[] { this.Map_Control1.Map, this.m_mapControl.Map };
                }
                //判断窗体是否打开(因为是非对话模式窗口)
                List<string> formNames = new List<string>();
                foreach (Form form in Application.OpenForms)
                {
                    formNames.Add(form.Name);
                }
                if (formNames.Contains("TPPP"))
                {
                    Application.OpenForms["TPPP"].Activate();
                }
                else
                {
                    //实例化选择集窗体
                    SJPP m_TuoPuPiPei = new SJPP(m_Maps, m_workspace.Datasources);
                    m_TuoPuPiPei.Name = "TPPP";
                    m_TuoPuPiPei.Crate_m_Xml();
                    m_TuoPuPiPei.FillSets();
                    //非模式窗体
                    m_TuoPuPiPei.Show();
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 数据集匹配
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Dataset_MatchingTopology_Click(object sender, EventArgs e)
        {
            try
            {
                //统计所有数据源中的数据集
                int count = 0;
                foreach (Datasource datasource in m_workspace.Datasources)
                {
                    count += datasource.Datasets.Count;
                }
                if (count > 1)
                {
                    //实例化数据集窗体，传递当前的数据源集合
                    SJPP m_TuoPuPiPei = new SJPP(m_workspace.Datasources);
                    m_TuoPuPiPei.Name = "TPPP";
                    m_TuoPuPiPei.Crate_m_Xml();
                    m_TuoPuPiPei.FillSets();
                    //对话模式窗体
                    m_TuoPuPiPei.ShowDialog();
                    m_TuoPuPiPei.Dispose();
                }
                else
                {
                    MessageBox.Show("数据源数据集不足！", "提示：");
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 刷新树视图
        /// </summary>
        public void RefreshWorkspaceTree()
        {
            try
            {
                if (this.WorkspaceTree_Control.WorkspaceTree.DatasourcesNode.Nodes[0].Nodes["NetworkDataset_1"] != null)
                {
                    this.WorkspaceTree_Control.WorkspaceTree.DatasourcesNode.Nodes[0].Nodes["NetworkDataset_1"].Remove();
                }
                if (this.WorkspaceTree_Control.WorkspaceTree.DatasourcesNode.Nodes[0].Nodes["NetworkDataset_2"] != null)
                {
                    this.WorkspaceTree_Control.WorkspaceTree.DatasourcesNode.Nodes[0].Nodes["NetworkDataset_2"].Remove();
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
        #endregion

        #region 数据融合
        /// <summary>
        /// 数据融合
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DataFusion_Click(object sender, EventArgs e)
        {
            try
            {
                int setCount = 0;
                foreach (Datasource datasource in m_workspace.Datasources)
                {
                    setCount += datasource.Datasets.Count;
                }
                if (setCount<2)
                {
                    MessageBox.Show("当前数据源中数据集不足！", "警告：");
                }
                else
                {
                    //实例化数据融合窗体
                    SJRH m_SJRH = new SJRH(m_workspace.Datasources);
                    //对话模式窗体
                    m_SJRH.ShowDialog();
                    //刷新一下数据源
                    m_workspace.Datasources[0].Refresh();
                    m_SJRH.Dispose();
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
        /// <summary>
        /// 将已进行的匹配结果存放到结果集中
        /// </summary>
        /// <param name="datasetsMatchResult">匹配结果</param>
        public void DatasetsMatchResultAdd(DatasetsMatchResult datasetsMatchResult)
        {
            try
            {
                if(datasetsMatchResults != null)
                {
                    for (int i = 0; i < datasetsMatchResults.Count; i++)
                    {
                        //检查是否存在
                        string names = datasetsMatchResults[i].Set1Name + datasetsMatchResults[i].Set2Name;
                        if (names==datasetsMatchResult.Set1Name + datasetsMatchResult.Set2Name)
                        {
                            //存在则更新属性
                            if (datasetsMatchResult.MatchSpaceResult != null)
                            {
                                datasetsMatchResults[i].MatchSpaceResult = datasetsMatchResult.MatchSpaceResult;
                            }
                            if (datasetsMatchResult.MatchAttributeResult != null)
                            {
                                datasetsMatchResults[i].MatchAttributeResult = datasetsMatchResult.MatchAttributeResult;
                                datasetsMatchResults[i].MatchAttributeFieldResult = datasetsMatchResult.MatchAttributeFieldResult;
                            }
                            if (datasetsMatchResult.MatchTopologyResult != null)
                            {
                                datasetsMatchResults[i].MatchTopologyResult = datasetsMatchResult.MatchTopologyResult;
                            }
                        }
                        else
                        {
                            //不存在则添加
                            datasetsMatchResults.Add(datasetsMatchResult);
                        }
                    }
                }
                else
                {
                    //先实例化再添加
                    datasetsMatchResults = new List<DatasetsMatchResult>();
                    datasetsMatchResults.Add(datasetsMatchResult);
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
        #endregion

        #region 关于
        /// <summary>
        /// 帮助
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Help_Click(object sender, EventArgs e)
        {
            try
            {
                Help m_help = new Help();
                m_help.ShowDialog();
                m_help.Dispose();
            }
            catch (Exception)
            {

                throw;
            }

        }
        /// <summary>
        /// 导航至supermap官网
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void SuperMap_About_Click(object sender, EventArgs e)
        {
            try
            {
                //超图官网
                Process.Start("https://www.supermap.com");
            }
            catch (Exception)
            {

                throw;
            }
        }


        #endregion

        #endregion

    }
}
